<template>
  <div class="playlist-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <img :src="playlist.coverImgUrl" alt />
      </div>
      <div class="info-wrap">
        <p class="title">{{playlist.name}}</p>
        <div class="author-wrap">
          <img class="avatar" :src="playlist.creator.avatarUrl" alt />
          <span class="name">{{playlist.creator.nickname}}</span>
          <span class="time">{{playlist.createTime}} 创建</span>
        </div>
        <div class="play-wrap">
          <span class="iconfont icon-circle-play"></span>
          <span class="text">播放全部</span>
        </div>
        <div class="tag-wrap">
          <span class="title">标签:</span>
          <ul>
            <li v-for="(item,i) in playlist.tags" :key="i">{{item}}</li>
          </ul>
        </div>
        <div class="desc-wrap">
          <span class="title">简介:</span>
          <span class="desc">{{playlist.description}}</span>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeIndex">
      <el-tab-pane label="歌曲列表" name="1">
        <table class="el-table playlit-table">
          <thead>
            <th></th>
            <th></th>
            <th>音乐标题</th>
            <!-- <th>歌手</th> -->
            <th>专辑</th>
            <th>时长</th>
          </thead>
          <tbody>
            <tr class="el-table__row" v-for="(item,i) in songs" :key="i">
              <td>1</td>
              <td>
                <div class="img-wrap">
                  <img :src="item.al.picUrl" alt />
                  <span class="iconfont icon-play" @click="playMusic(item.id)"></span>
                </div>
              </td>
              <td>
                <div class="song-wrap">
                  <div class="name-wrap">
                    <span>{{item.name}}</span>
                    <span class="iconfont icon-mv"></span>
                  </div>
                  <!-- <span>电视剧加油练习生插曲</span> -->
                </div>
              </td>
              <!-- <td>{{playlist.name}}</td> -->
              <td>{{item.al.name}}</td>
              <td>03:30</td>
            </tr>
          </tbody>
        </table>
      </el-tab-pane>
      <el-tab-pane label="评论(66)" name="2">
        <!-- 精彩评论 -->
        <div class="comment-wrap">
          <p class="title">
            精彩评论
            <span class="number">({{hotCount}})</span>
          </p>
          <div class="comments-wrap">
            <div class="item" v-for="(item,i) in hotComment" :key="i">
              <div class="icon-wrap">
                <img :src="item.user.avatarUrl" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{item.user.nickname}}：</span>
                  <span class="comment">{{item.content}}</span>
                </div>
                <!-- 评论回复 -->
                <div class="re-content" v-if="item.beReplied.length!=0">
                  <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                  <span class="comment">{{item.beReplied[0].content}}</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 最新评论 -->
        <div class="comment-wrap">
          <p class="title">
            最新评论
            <span class="number">({{total}})</span>
          </p>
          <div class="comments-wrap">
            <div class="item" v-for="(item,i) in comments" :key="i">
              <div class="icon-wrap">
                <img :src="item.user.avatarUrl" alt />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{item.user.nickname}}：</span>
                  <span class="comment">{{item.content}}</span>
                </div>
                <div class="re-content" v-if="item.beReplied.length!=0">
                  <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                  <span class="comment">{{item.beReplied[0].content}}</span>
                </div>
                <div class="date">2020-02-12 17:26:11</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页器 -->
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="5"
        ></el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
 
<script>
// import axios from "axios";
import { playMusic,getPlaylistDetail,getHotComment,getNewComment} from '../network/playlist'
import {mapMutations} from 'vuex'
export default {
  name: "playlist",
  data() {
    return {
      activeIndex: "1",
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 歌单详情
      playlist: {
        creator: {},
      },
      // tracks歌曲列表
      songs: [],
      // 热门评论
      hotComment: [],
      // 热门评论个数
      hotCount: 0,
      // 最新评论
      comments: [],
    };
  },
  methods: {
    ...mapMutations(['setUrl','setIsPlay']),
    // 播放歌曲
    playMusic(id) {
      // axios({
      //   url: "https://autumnfish.cn/song/url",
      //   method: "get",
      //   params: { id },
      // }).then((res) => {
      //   console.log(res);
      //   let url = res.data.data[0].url;
      //   this.$parent.musicUrl = url;
      // });
       playMusic(id).then(res=>{
         let url = res.data.data[0].url;
        // this.$parent.musicUrl = url;
        this.setUrl(url)
        if (this.isPlay) {
          this.setIsPlay(false);
        } else {
          this.setIsPlay(true);
        }
       })
    },
    handleCurrentChange(val) {
      this.page = val;

      // axios({
      //   url: "https://autumnfish.cn/comment/playlist",
      //   method: "get",
      //   params: {
      //     id: this.$route.query.q,
      //     limit: 10,
      //     offset: (this.page - 1) * 10,
      //   },
      // }).then((res) => {
      //   console.log(res);
      //   // 最新评论总数
      //   this.total = res.data.total;
      //   // 最新评论数据
      //   this.comments = res.data.comments;
      // });
      getNewComment(this.$route.query.q,10,(this.page - 1) * 10).then(res=>{
        // console.log(res);
      //   // 最新评论总数
        this.total = res.data.total;
      //   // 最新评论数据
        this.comments = res.data.comments;
      })
    },
  },
  created() {
    // 获取歌单
    // axios({
    //   url: "https://autumnfish.cn/playlist/detail",
    //   method: "get",
    //   params: { id: this.$route.query.q },
    // }).then((res) => {
    //   console.log(res);
    //   this.playlist = res.data.playlist;
    //   this.songs = res.data.playlist.tracks;
    //   console.log(this.songs);
    // });
    getPlaylistDetail(this.$route.query.q).then(res=>{
      //  console.log(res);
      this.playlist = res.data.playlist;
      this.songs = res.data.playlist.tracks;
    //   console.log(this.songs);
    })

    // 获取热门评论
    // axios({
    //   url: "https://autumnfish.cn/comment/hot",
    //   method: "get",
    //   params: { id: this.$route.query.q, type: 2 },
    // }).then((res) => {
    //   // console.log(res);
    //   this.hotComment = res.data.hotComments;
    //   // 热门评论个数
    //   this.hotCount = res.data.total;
    // });
    getHotComment(this.$route.query.q,2).then(res=>{
       this.hotComment = res.data.hotComments;
    //   // 热门评论个数
      this.hotCount = res.data.total;
    })

    // 获取最新评论
    // axios({
    //   url: "https://autumnfish.cn/comment/playlist",
    //   method: "get",
    //   params: { id: this.$route.query.q, limit: 10, offset: 0 },
    // }).then((res) => {
    //   // console.log(res);
    //   // 最新评论总数
    //   this.total = res.data.total;
    //   // 最新评论数据
    //   this.comments = res.data.comments;
    // });
    getNewComment(this.$route.query.q,10,0).then(res=>{
      // 最新评论总数
      this.total = res.data.total;
    //   // 最新评论数据
      this.comments = res.data.comments;
    })
  },
};
</script>

<style >
</style>
